package com.res.demo;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TableListAdapter extends ArrayAdapter<TableModel> {

	List<TableModel> list;
	Activity context;
	LayoutInflater inflate;

	public TableListAdapter(Activity context, List<TableModel> list) {
		super(context, R.layout.table_item, list);
		this.list = list;
		this.context = context;

		inflate = context.getLayoutInflater();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View rowView = convertView;
		final ViewHolder holder;
		TableModel model = list.get(position);
		if (rowView == null) {
			rowView = inflate.inflate(R.layout.table_item, null, true);
			holder = new ViewHolder();
			holder.name = (TextView) rowView.findViewById(R.id.tableName);
		
			rowView.setTag(holder);
		} else {
			holder = (ViewHolder) rowView.getTag();
		}

		holder.name.setText(model.getName());
		rowView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		return rowView;
	}

	class ViewHolder {
		TextView name;
		
	}
}
